package org.metasketch.demo.project.load;

import java.io.File;
import org.metasketch.demo.model.DEMOModel;
import org.metasketch.demo.project.DEMOProject;
import org.metasketch.logger.Log;
import org.metasketch.model.loader.DefaultModelReader;
import org.metasketch.model.loader.IGraphDatabase;
import org.metasketch.model.loader.transform.ModelTransformer;

public class DEMOModelLoader {

	public static DEMOModel loadModel(File file, DEMOProject project)
			throws Throwable {
		Log.print("Loading model: " + file.getName() + "...");

		DefaultModelReader reader = new DefaultModelReader();
		IGraphDatabase modelGraph = reader.readFile(file);

		Log.println("done.");

		Log.print("Creating model: " + file.getName() + "...");
		// transform graph into model

		DEMOModel model = new DEMOModel();

		ModelTransformer.transform(modelGraph, model, "Package", "org.metasketch.demo.model.", true);

		Log.println("done.");

		project.setModel(model);

		return model;

	}

}
